<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="Bookmark" href="/favicon.ico">
		<link rel="Shortcut Icon" href="/favicon.ico" />
		<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
		<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
		<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
		<!--/meta 作为公共模版分离出去-->

		<title>添加用户 - 胆款流转实时监控管理系统 v1.0</title>
		<meta name="keywords" content="胆款流转实时监控管理系统 v1.0">
		<meta name="description" content="胆款流转实时监控管理系统 v1.0">
	</head>

	<body>
		<article class="page-container">
			<!-- <form action="/apis/base/cashbox/createCashbox" method="post" class="form form-horizontal" id="form-cashbox-add"> -->
			<form action="" method="post" class="form form-horizontal"
			 id="form-cashbox-add">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;"><span class="c-red">*</span>钱胆类型：</label>
					<div class="formControls col-xs-8 col-sm-9 skin-minimal">
						<div class="radio-box">
							<input name="type" type="radio" id="type-1" value="C" checked>
							<label for="type-1">钱胆</label>
						</div>
						<div class="radio-box">
							<input type="radio" id="type-2" name="type" value="R">
							<label for="type-2">款包</label>
						</div>
						<div class="radio-box">
							<input type="radio" id="type-3" name="type" value="P">
							<label for="type-3">大包</label>
						</div>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;">分公司：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
							<select class="select" id="comId" name="comId">
								<option value="" selected>请选择分公司</option>
							</select>
						</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;">票务室：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
							<select class="select" id="toId" name="toId">
								<option value="" selected>请选择票务室</option>
							</select>
						</span>
					</div>
				</div>
				<!-- <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;">当前截止号：</label>
					<div class="formControls col-xs-8 col-sm-9" id="crp_id">
						
					</div>
				</div> -->
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;"><span class="c-red">*</span>胆号：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<!--<input type="text" class="input-text" value="" placeholder="例如:0001/0010" id="id">-->
						起号：<input style="width: 30%;" class="input-text" type="number" min="1" id="startCode" name="startCode"><span id="">
							/
						</span> 止号：
						<input style="width: 30%;" class="input-text" type="number" min="1" id="endCode" name="endCode">
						<span style="color: red;display: block;">[注：起止号为1~9999999之间七位数字]</span>
					</div>

				</div>

				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;"><span class="c-red">*</span>状态：</label>
					<div class="formControls col-xs-8 col-sm-9 skin-minimal">
						<div class="radio-box">
							<input name="status" type="radio" value="1" id="status-1" checked>
							<label for="status-1">启用</label>
						</div>
						<div class="radio-box">
							<input name="status" type="radio" value="0" id="status-2">
							<label for="status-2">停用</label>
						</div>
					</div>
				</div>

				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3" style="width: 20%;">备注：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<textarea name="summary" cols="" rows="" class="textarea" placeholder="说点什么...最少输入10个字符"></textarea>
						<!-- onKeyUp="$.Huitextarealength(this,100)"-->
						<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3" style="margin-left: 0;text-align: center;vertical-align: middle;width: 100%;">
						<input id="submit_btn" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					</div>
				</div>
			</form>
		</article>

		<!--_footer 作为公共模版分离出去-->
		<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
		<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
		<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
		<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
		<!--/_footer 作为公共模版分离出去-->

		<!--请在下方写此页面业务相关的脚本-->
		<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
		<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
		<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
		<script type="text/javascript" src="js/jquery.base64.js"></script>
		<script type="text/javascript">
			//本地调试
			//var urlsCashbox = 'http://localhost:8000/cashbox/';
			//调用report服务中的分公司与票务室方法
			//var urlsReport = 'http://localhost:8800/report/';
			//阿里云调试
			//var urlsReport = 'http://39.100.91.49:8800/report';
			//上线部署
			var urlsCashbox = '/apis/base/cashbox/';
			var urlsReport = '/apis/report/report';

			$(function() {
				$('.skin-minimal input').iCheck({
					checkboxClass: 'icheckbox-blue',
					radioClass: 'iradio-blue',
					increaseArea: '20%'
				});

				//查询分公司
				$.ajax({
					type: 'GET',
					url: urlsReport + '/getAllCompany',
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					},
					dataType: 'json',
					success: function(data) {
						var list = eval('(' + data.list + ')');
						for (var i = 0; i < list.length; i++) {
							$("#comId").append("<option value='" + list[i].companyid + "'>" + list[i].companyname + "</option>");
						}
					},
					error: function(data) {
						console.log(data.msg);
					}
				});
				//查询票务室
				$("#comId").change(function() {
					$("#toId").empty();
					var comId = $(this).val();
					var targetUrl = urlsReport + '/getTicktOfficeByCom';
					/* if(comId == '') {
						//$("#toId").fadeOut("slow");
						return;
					} */
					$.ajax({
						type: 'get',
						url: targetUrl,
						data: {
							"comId": comId
						},
						cache: false,
						beforeSend: function(request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						},
						dataType: 'json',
						success: function(data) {
							//var list = data.list;
							var list = eval('(' + data.list + ')');
							var option ='<option value="" selected>请选择票务室</option>';
							for (var i = 0; i < list.length; i++) {
								option+= '<option value="' + list[i].toiid + '">' + list[i].toiname + '</option>';
								
							}
							$("#toId").append(option);
						},
						error: function() {
							//alert("请求失败");
						}
					});
				});
				//查询钱胆/款包/大包已存在的最大值
				/* var maxClist="";
				var maxRlist="";
				var maxPlist="";
				$.ajax({
					type: 'GET',
					url: urlsCashbox + 'getMax',
					 beforeSend: function(request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					}, 
					dataType: 'json',
					success: function(data) {
						maxClist=data.maxClist;
						maxRlist=data.maxRlist;
						maxPlist=data.maxPlist;
						console.log(JSON.stringify(data))
							$("#crp_id").append("<span>钱胆：[ "+maxClist.substring(1,maxClist.length)+" ]</span><span>&nbsp;&nbsp;款包：[ "+maxRlist.substring(1,maxRlist.length)+" ]</span><span>&nbsp;&nbsp;大包：[ "+maxPlist.substring(1,maxPlist.length)+" ]</span>");
						
					},
					error: function(data) {
						console.log(data);
					}
				}); */

				$("#form-cashbox-add").validate({
					rules: {},
					onkeyup: false,
					focusCleanup: true,
					success: "valid",
					submitHandler: function(form) {
						/* if($("#comId").val() == '') {
							alert("请选择分公司！")
							return;
						} */
						var startCode = document.getElementById("startCode");
						//console.log("起号长度："+startCode.value.length)
						if (startCode.value.length == 0) {
							alert("请输入起号！")
							return;
						}
						if (startCode.value.length > 7) {
							alert("大于7位，请重新输入起号！")
							return;
						}
						var endCode = document.getElementById("endCode");
						if (endCode.value.length == 0) {
							alert("请输入止号！")
							return;
						}
						if (endCode.value.length > 7) {
							alert("大于7位，请重新输入止号！")
							return;
						}
						if (endCode.value < startCode.value) {
							alert("止号不能小于起号，请重新输入！")
							return;
						}
						/* var crp_type = $("input[name='type']:checked").val();
						console.log(crp_type)
						if(crp_type == "1"){
							if(startCode.value<=maxClist.substring(1,maxClist.length)) {
								alert("钱胆——起号小于已存在的最大值，请重新输入！")
								return;
							}
						}else if(crp_type=="2"){
							if(startCode.value<=maxRlist.substring(1,maxRlist.length)) {
								alert("款包——起号小于已存在的最大值，请重新输入！")
								return;
							}
						}else{
							if(startCode.value<=maxPlist.substring(1,maxPlist.length)) {
								alert("大包——起号小于已存在的最大值，请重新输入！")
								return;
							}
						}
						 */
						var postData = $("#form-cashbox-add").serialize();
						$.ajax({
							type: 'POST',
							url: urlsCashbox + "createCashboxsByCashboxIdRange",
							data: postData,
							cache: false,
							/* beforeSend: function(request) {
								request.setRequestHeader("Authorization", "Bearer " + getToken());
							}, */
							dataType: 'json',
							success: function(data) {
								console.log("返回的数据：" + data)
								//alert(JSON.stringify(data));
								if (data.maxCList) {
									//$("#form-cashbox-add").ajaxSubmit();
									layer.msg('添加成功!', {
										icon: 1,
										time: 1000
									}, function() {
										var index = parent.layer.getFrameIndex(window.name);
										parent.$('.btn-refresh').click();
										parent.layer.close(index);
									});
									
								} else {
									alert("提交失败，请重新提交！")
								}
							},
							error: function() {
								alert("请求失败");
							}
						});

					}
				});
			});
		</script>
		<!--/请在上方写此页面业务相关的脚本-->
	</body>

</html>
